package model;

public class Computer {
    private String id;
    private String brand;
    private String model;
    private String configuration;
    private double price;
    private int stock;

    public Computer(String id, String brand, String model, String configuration, double price, int stock) {
        this.id = id;
        this.brand = brand;
        this.model = model;
        this.configuration = configuration;
        this.price = price;
        this.stock = stock;
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getConfiguration() {
        return configuration;
    }

    public void setConfiguration(String configuration) {
        this.configuration = configuration;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    @Override
    public String toString() {
        return id + "," + brand + "," + model + "," + configuration + "," + price + "," + stock;
    }

    public static Computer fromString(String data) {
        String[] parts = data.split(",");
        if (parts.length == 6) {
            return new Computer(parts[0], parts[1], parts[2], parts[3],
                    Double.parseDouble(parts[4]), Integer.parseInt(parts[5]));
        }
        return null;
    }
}